﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Web.Http;
using System.IO;
using System.Web;
using System.Threading.Tasks;
using System.Data;
using BartonExtension;
using ResponseObject;
using MySql.Data.MySqlClient;
using MySql.Data;
using SQLWrapper;

using WSServer;

using Model;
using WeixinModel;

namespace XiJiaXi.Controllers
{
    public class ShareController : ApiController
    {
        [HttpPost]
        public async Task<ZKResponse> OnShare(WeixinUser share)
        {
            ZKResponse response = await Task.Factory.StartNew<ZKResponse>(() =>
                {
                    ZKResponse resp = new ZKResponse();
                    Wedding wedding = WeddingContainer.sharedInstance.WeddingWithIdentifier(share.wedding_id);
                    if(wedding == null)
                    {
                        wedding = Wedding.New(share.wedding_id);
                    }
                    resp.isProcessSuccess = wedding.AddShare(share);
                    return resp;
                });
            if(response.isProcessSuccess)
            {
                await PushService.PushOnScreenStatToWedding(share.wedding_id,share);
            }
            return response;
        }
    }
}
